<!DOCTYPE html>
<html>
<head>
    <title>历史</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <#--样式-->
    <link rel="stylesheet" media="screen" href="${request.contextPath}/css/style.css">
    <#--layui-->
    <link rel="stylesheet" media="screen" href="${request.contextPath}/layui/css/layui.css">

</head>
<body >





    <div class="content" >



       <div >
           <#--月亮放置区-->
           <div class="light" style="cursor:pointer;" onclick="window.location.href = '/history/'">
           </div>

           <hr class="line-left">
           <hr class="line-right">

           <div class="main">
               <h1 class="title">更新年号</h1>
           </div>




           <div class="textContent" style="padding-bottom: 300px;">

               <div style="width: 900px;">

                   <form class="layui-form" id="formReignTitle">
                       <input required lay-verify="required" type="hidden" name="id" value="${reignTitle.id!''}">




                       <div class="layui-form-item">
                           <label class="layui-form-label">历史主线</label>
                           <div class="layui-input-block">
                               <select name="historyId" lay-filter="aihao" lay-search>
                                   <option value="">请选择历史主线</option>
                                   <#if historyMainList??>
                                       <#list historyMainList as historyMain>
                                           <#if historyMain??>
                                               <#if historyMain.ad == 1>
                                                   <#if historyMain.accuracy == 1>
                                                       <option value="${historyMain.id!''}" <#if reignTitle.historyId == historyMain.id>selected="selected"</#if> >约 公元元年</option>
                                                   <#else >
                                                       <option value="${historyMain.id!''}" <#if reignTitle.historyId == historyMain.id>selected="selected"</#if> >公元元年</option>
                                                   </#if>

                                               <#elseif historyMain.ad < 0>
                                                   <#if historyMain.accuracy == 1>
                                                       <option value="${historyMain.id!''}" <#if reignTitle.historyId == historyMain.id>selected="selected"</#if> >约 公元前 ${historyMain.ad!''} 年</option>
                                                   <#else >
                                                       <option value="${historyMain.id!''}" <#if reignTitle.historyId == historyMain.id>selected="selected"</#if> >公元前 ${historyMain.ad!''} 年</option>
                                                   </#if>

                                               <#else >
                                                   <#if historyMain.accuracy == 1>
                                                       <option value="${historyMain.id!''}" <#if reignTitle.historyId == historyMain.id>selected="selected"</#if> >约 公元 ${historyMain.ad!''} 年</option>
                                                   <#else >
                                                       <option value="${historyMain.id!''}" <#if reignTitle.historyId == historyMain.id>selected="selected"</#if> >公元 ${historyMain.ad!''} 年</option>
                                                   </#if>

                                               </#if>
                                           </#if>
                                       </#list>
                                   </#if>
                               </select>
                           </div>
                       </div>



                       <hr class="layui-bg-orange">

                       <div class="layui-form-item layui-form-text">
                           <label class="layui-form-label">帝王</label>
                           <div class="layui-input-block">
                               <input value="${reignTitle.emperor!''}" type="text" name="emperor" required lay-verify="required" placeholder="对应的帝王，必填" autocomplete="off" class="layui-input">
                           </div>
                       </div>

                       <div class="layui-form-item layui-form-text">
                           <label class="layui-form-label">年号</label>
                           <div class="layui-input-block">
                               <input value="${reignTitle.regin!''}" type="text" name="regin" required lay-verify="required"  placeholder="年号，比如贞观三年。必填" autocomplete="off" class="layui-input">
                           </div>
                       </div>




                       <br/>
                       <br/>


                       <div class="layui-form-item">
                           <div class="layui-input-block">
                               <button class="layui-btn" lay-submit lay-filter="updReignTitle">修改</button>
                               <button class="layui-btn layui-btn-danger" type="button" onclick="delReignTitle()" >删除</button>
                           </div>
                       </div>

                   </form>

               </div>




           </div>



       </div>
    </div>




</body>


<!-- scripts -->

<#--layui-->
<script src="${request.contextPath}/layui/layui.js"></script>
<#--js-->
<script src="${request.contextPath}/js/jquery.min.js"></script>


<script>


    // 引入弹出层
    var form = null;
    layui.use('form', function(){
        form = layui.form;

        /**
         * 监听提交,更新年号
         */
        form.on('submit(updReignTitle)', function(data){
            $.ajax({
                url:'/history/other/updReignTitle', //请求的url地址
                dataType:'json', //返回的格式
                data: $("#formReignTitle").serialize(),//参数值 {"id":"value"}
                type:'post', //请求的方式
                beforeSend:function(){ //请求前的处理
                    console.log("提交的数据:" + JSON.stringify(data.field))
                },
                success:function (req) {
                    if (req != null){
                        if (req.status === "success"){
                            layer.msg(req.msg);
                        } else {
                            layer.msg(req.msg);
                        }
                    } else {
                        console.log(req);
                    }
                },
                error:function (e) {
                    console.log(e);
                    layer.msg("未知错误");
                }
            });

            //返回false则不会重置
            return false;
        });
    });


    /**
     * 删除 年号
     */
    function delReignTitle() {
        var id = $("input[name='id']").val();
        if (id === null || id === ""){
            layer.msg("数据异常，请刷新后重试");
            return;
        }

        layer.confirm('确认是否删除年号，注意：删除后不可恢复?', {icon: 3, title:'警告'}, function(index){
            $.ajax({
                url:'/history/other/delReignTitle', //请求的url地址
                dataType:'json', //返回的格式
                data: {"id" : id},//参数值 {"id":"value"}
                type:'get', //请求的方式
                beforeSend:function(){ //请求前的处理
                    console.log("提交的数据:" + id)
                },
                success:function (req) {
                    if (req != null){
                        if (req.status === "success"){
                            layer.msg(req.msg);

                        } else {
                            layer.msg(req.msg);
                        }
                    } else {
                        console.log(req);
                    }
                },
                error:function (e) {
                    console.log(e);
                    layer.msg("未知错误");
                }

            });

            layer.close(index);
        });
    }

</script>



</html>